package com.shxzz.shortlink.project.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shxzz
 * @create 2023-12-18-15:04
 * @description 布隆过滤器配置
 */
@Configuration
public class RBloomFilterConfiguration {

    /**
     * 短链接布隆过滤器，防止短链接生成重复短链接
     */
    @Bean
    public RBloomFilter<String> linkGenerateCachePenetrationRBloomFilter(RedissonClient redissonClient) {
        RBloomFilter<String> linkGenerateCachePenetration = redissonClient
                .getBloomFilter("linkGenerateCachePenetration");

        linkGenerateCachePenetration.tryInit(100000000L,0.001);

        return linkGenerateCachePenetration;
    }
}
